package com.anosine.gpsl.android.ui.fragment;

import java.io.Serializable;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.anosine.gpsl.android.R;
import com.anosine.gpsl.android.base.BaseFragment;
import com.anosine.gpsl.android.entity.PushMessageBean;
import com.anosine.gpsl.android.util.BundleKey;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
/**
 * @Title: ShowReceivePushFragment
 * @Package com.anosine.gpsl.android.ui.fragment
 * @Description:
 * @author: sunny
 * @date: 2015-11-23
 * @version V1.0
 */
public class ShowReceivePushFragment extends BaseFragment {
	@ViewInject(R.id.Message_title)
	TextView mTvTitle;
	@ViewInject(R.id.Message_date)
	TextView mTvDate;
	@ViewInject(R.id.Message_context)
	TextView mTvContext;
	@ViewInject(R.id.url_go)
	TextView mUrlGo;	
	@ViewInject(R.id.back)
	ImageView back;
	/**
	 * 方法名：onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
	 * savedInstanceState) 功 能：创建该Fragment的视图 参 数：LayoutInflater inflater
	 * LayoutInflater是用来找res/layout/下的xml布局文件，并且实例化 ViewGroup container
	 * ViewGroup是Layout的基类, Bundle savedInstanceState 返回值： View view
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_receive_push, null);
		ViewUtils.inject(this,view);
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				getActivity().getSupportFragmentManager().popBackStack();
			}
		});
		Serializable pmb = getArguments().getSerializable(
				BundleKey.TAG_SCENERY_DATA);
		PushMessageBean bean = (PushMessageBean) pmb;

		if (bean != null) {
			mTvTitle.setText(bean.getTitle());
			mTvDate.setText(bean.getDate());
			if(bean.getDesc()!=null){	
			if (bean.getDesc().contains("$url$")) {
				final String[] getUrl = bean.getDesc().split("\\$url\\$");
				String content = "";
				if (getUrl.length != 0) {
					for (int i = 0; i < getUrl.length - 1; i++) {
						content = content + getUrl[i];
					}
					mUrlGo.setVisibility(View.VISIBLE);
					mTvContext.setText(content);
					mUrlGo.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View arg0) {
							Uri uri = Uri.parse(getUrl[getUrl.length - 1]);
							Intent it = new Intent(Intent.ACTION_VIEW, uri);
							startActivity(it);

						}
					});
				} else {
					mTvContext.setText(bean.getDesc());
				}
			} else {
				mUrlGo.setVisibility(View.GONE);
				mTvContext.setText(bean.getDesc());
			}
			}
		}
		return view;
	}


}
